package com.jxb.controller;

import com.jxb.service.ReqDO;
import com.jxb.service.Service;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class SearchController {

    @Resource
    private Service service;

    /**
     * 测试结果：
     * {
     * 	"took": 3,
     * 	"timed_out": false,
     * 	"_shards": {
     * 		"total": 1,
     * 		"successful": 1,
     * 		"skipped": 0,
     * 		"failed": 0
     *        },
     * 	"hits": {
     * 		"total": {
     * 			"value": 1,
     * 			"relation": "eq"
     *        },
     * 		"max_score": null,
     * 		"hits": [{
     * 			"_index": "product_db",
     * 			"_type": "_doc",
     * 			"_id": "16",
     * 			"_score": null,
     * 			"_source": {
     * 				"id": "41",
     * 				"name": "华为P40 Pro手机",
     * 				"keywords": "华为手机",
     * 				"subTitle": "华为P40 Pro手机",
     * 				"price": "2129",
     * 				"promotionPrice": "2139",
     * 				"originalPrice": "2149",
     * 				"pic": "http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/images/20180607/5ac1bf58Ndefaac16.jpg",
     * 				"sale": 999,
     * 				"hasStock": true,
     * 				"salecount": 199,
     * 				"putawayDate": "2021-05-03",
     * 				"brandId": 3,
     * 				"brandName": "华为",
     * 				"brandImg": "http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/images/20190129/17f2dd9756d9d333bee8e60ce8c03e4c_222_222.jpg",
     * 				"categoryId": 19,
     * 				"categoryName": "手机通讯",
     * 				"attrs": [{
     * 					"attrId": 9,
     * 					"attrName": "容量",
     * 					"attrValue": "128G"
     *                }, {
     * 					"attrId": 10,
     * 					"attrName": "网络",
     * 					"attrValue": "5G"
     *                }]
     *            },
     * 			"highlight": {
     * 				"keywords": ["华为<span style='color:red'>手机</span>"],
     * 				"subTitle": ["华为P40 Pro<span style='color:red'>手机</span>"],
     * 				"name": ["华为P40 Pro<span style='color:red'>手机</span>"]
     *            },
     * 			"sort": [199, 2129.0, 1620000000000]
     *        }]
     *    },
     * 	"aggregations": {
     * 		"lterms#brand_agg": {
     * 			"doc_count_error_upper_bound": 0,
     * 			"sum_other_doc_count": 0,
     * 			"buckets": [{
     * 				"key": 3,
     * 				"doc_count": 1,
     * 				"sterms#brand_img_agg": {
     * 					"doc_count_error_upper_bound": 0,
     * 					"sum_other_doc_count": 0,
     * 					"buckets": [{
     * 						"key": "http://macro-oss.oss-cn-shenzhen.aliyuncs.com/mall/images/20190129/17f2dd9756d9d333bee8e60ce8c03e4c_222_222.jpg",
     * 						"doc_count": 1
     *                    }]
     *                },
     * 				"sterms#brand_name_agg": {
     * 					"doc_count_error_upper_bound": 0,
     * 					"sum_other_doc_count": 0,
     * 					"buckets": [{
     * 						"key": "华为",
     * 						"doc_count": 1
     *                    }]
     *                }
     *            }]
     *        }
     *    }
     * }
     *
     * @param reqDO
     * @return java
     * .lang.Object
     * @author jiaobo
     * @date 2024/9/27 21:06
     */
    @RequestMapping("/search")
    @ResponseBody
    public Object search(@RequestBody ReqDO reqDO) {
        return service.search(reqDO);
    }

}
